package com.hzp.lolnews.ui.discovery.view;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hzp.lolnews.R;
import com.hzp.lolnews.base.BaseRecyclerViewHolder;
import com.hzp.lolnews.bean.DiscoveryContent;

import java.util.List;

/**
 * Created by Administrator on 2016/10/21 0021.
 */
public class DiscoveryContentAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {

    private List<DiscoveryContent> mList;
    private Context mContent;
    public DiscoveryContentAdapter(Context context){
        this.mContent = context;
    }

    public void setData(List<DiscoveryContent> list) {
        this.mList = list;
        notifyDataSetChanged();
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_dis_content, parent, false);
        return new BaseRecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder holder, int position) {
        DiscoveryContent discoveryContent = mList.get(position);
        List<DiscoveryContent.DataBean> data = mList.get(position).getData();
        Log.i("TAG", "onBindViewHolder:=============================== " + data);
        TextView tvName = holder.getView(R.id.dis_inner_tvName);
        tvName.setText(discoveryContent.getName());
        RecyclerView innerRecycler = holder.getView(R.id.dis_inner_contentRecycler);
        StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.HORIZONTAL);
        innerRecycler.setLayoutManager(manager);
        DiscoveryInnerContentAdapter adapter = new DiscoveryInnerContentAdapter();
        adapter.setData(data,mContent);
        innerRecycler.setAdapter(adapter);

    }

    @Override
    public int getItemCount() {
        return mList != null ? mList.size() : 0;
    }
}
